﻿if exists (select * from dbo.sysobjects 
where id = object_id(N'[dbo].[udf_OrderDetailsExtended]') and 
      xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[udf_OrderDetailsExtended]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION udf_OrderDetailsExtended 
(	
)
-- select * from udf_OrderDetailsExtended()
RETURNS TABLE 
AS
RETURN 
(
	SELECT 
	[OrderDetail].OrderID, 
	[OrderDetail].ProductID, 
	Product.Name as ProductName, 
	[OrderDetail].UnitPrice, 
	[OrderDetail].Quantity, 
	[OrderDetail].Discount, 
	Cast(([OrderDetail].UnitPrice*[Quantity]*(1-[Discount])/100)*100 as money) AS ExtendedPrice
	FROM Product, [OrderDetail] 
	where Product.ID = [OrderDetail].ProductID
)
GO
